/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bpmlab.kivulifx.effects;

import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.input.MouseEvent;

/**
 *
 * @author bpmlab
 */
public class MoveShape {

    private double sceneX, sceneY;
    private double translateX, translateY;
    private EventHandler<MouseEvent> onMouseDragged;
    private EventHandler<MouseEvent> onMousePressed;

    public MoveShape() {
    }

    public EventHandler<MouseEvent> getOnMouseDragged() {
        onMouseDragged = (MouseEvent event) -> {
            double offsetX = event.getSceneX() - sceneX;
            double offsetY = event.getSceneY() - sceneY;
            double newTranslateX = translateX + offsetX;
            double newTranslateY = translateY + offsetY;
            Node node = (Node) event.getSource();
            node.setTranslateX(newTranslateX);
            node.setTranslateY(newTranslateY);
        };
        return onMouseDragged;
    }

    public EventHandler<MouseEvent> getOnMousePressed() {
        onMousePressed = (MouseEvent event) -> {
            sceneX = event.getSceneX();
            sceneY = event.getSceneY();
            Node node = (Node) event.getSource();
            translateX = node.getTranslateX();
            translateY = node.getTranslateY();
        };
        return onMousePressed;
    }

}
